#pragma once

#include "CQLogin.h"
#include <QtWidgets/QMainWindow>
#include <QtCore/QTimer>
#include <QtWidgets/QSystemTrayIcon>
#include <QtWidgets/QMenu>
#include <QtWidgets/QAction>
#include <string>
#include "ui_CQChat.h"

class CQChat :public QMainWindow, public CQBaseWin<CQChat>
{
	Q_OBJECT

public:
	CQChat(QWidget* parent = Q_NULLPTR);
	~CQChat();
	CQLogin* get_login_win();

private:
	void set_win_btn();
	void set_user_ui_info();
	void get_friend_list();

	void set_system_tray();
	void create_actions();
	void create_menu();
	void set_net_state(NetState);
	void sent_msg_to_all(const std::string &);
	bool fix_network();
	virtual void mousePressEvent(QMouseEvent*)override;
	virtual void mouseMoveEvent(QMouseEvent*)override;
	virtual void mouseReleaseEvent(QMouseEvent*)override;
	virtual void paintEvent(QPaintEvent*)override;
private slots:
	void window_closed();
	void window_min();
	void set_ui_time();
	void change_net_state();
	void system_tray_icon_clicked(QSystemTrayIcon::ActivationReason);

	void friend_list_double_click(QListWidgetItem* item);


	void on_show_main_action();
	void on_exit_action();
	void on_online_action();
	void on_offline_action();
	void on_restart_action();
	NetClient get_socket();
private:
	Ui::CQChatClass ui;
	CQLogin* login_win = nullptr;
	UserInfo u;
	QPixmap pic_online, pic_offline;
	QTimer* time_clock = nullptr;
	QSystemTrayIcon* tray_icon = nullptr;
	QMenu* mMenu = nullptr;
	QAction* mShowMainAction = nullptr;
	QAction* mExitAppAction = nullptr;
	QAction* mSetOnline = nullptr;
	QAction* mSetOffline = nullptr;
	QAction* mRestart = nullptr;
	NetClient sock;
};
